package com.cpit.qualitycontrol.dao;

import com.cpit.qualitycontrol.entity.SubTask;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * Created by xxx on 2017/10/1.
 */
public interface SubTaskCrudRepository extends JpaRepository<SubTask, Long> {

    List<SubTask> findByWorkOrderId(Long workOrderId);

    List<SubTask> findByDeviceId(String deviceId);

    List<SubTask>  findByOrganizationTeamId(Long organizationTeamId);

    Long countByWorkOrderTypeId(Long workOrderid);

    Long countByWorkOrderTypeIdAndDeviceId(Long workOrderTypeId, String deviceId);

    @Query("select count(s) from SubTask s, Device d where s.workOrderTypeId = ?1 and s.deviceId = d.id and d.deviceTypeId = ?2 and d.projectId = ?3")
    Long countByWorkOrderTypeIdAndDeviceTypeIdAndProjectId(Long workOrderTypeId, Long deviceTypeId, Long projectId);


}
